var Frogdivbackup = function(param){
    var dom = document.getElementById(param.domId);

    dom.style.position = 'absolute';
    window.onresize = function () {
        dom.style.display = 'none';
    }

    var obj = {
        zIndex : param.zIndex,
        domId : param.domId,
        reference : null,
        refBody : null,
        open : function (option) {
            var htmlStr = option.content;   // 浮窗内部的html
            var reference = option.reference;   // 参照的dom元素, 在这个dom旁边生成浮窗
            var direction = option.direction;   // 浮窗位置: up, down, left, right
            var fWidth = option.width || '100px';
            var fHeight = option.height || '100px';

            function getParent(dom, nodeName) {
                if(dom.parentNode.nodeName == nodeName){
                    return dom.parentNode;
                }else{
                    return getParent(dom.parentNode, nodeName);
                }
            }

            function position(target){    // 获取指定window对象相对于页面的绝对位置
                var frames = window.frames;
                for(var i = 0; i < frames.length; i++){
                    if(frames[i].frameElement.contentDocument == target){
                        var ifr = frames[i].frameElement;
                        var curIfr = ifr;
                        var left = 0, top = 0;

                        do {
                            left += ifr.offsetLeft || 0;
                            top += ifr.offsetTop || 0;
                            ifr = ifr.offsetParent;
                        } while(ifr);

                        return {
                            ifr : curIfr,
                            left: left,
                            top: top
                        };
                    }
                }
            }

            this.refBody = getParent(reference, "BODY");
            this.reference = reference;

            dom.style.zIndex = this.zIndex + 1;
            var pos = position(getParent(this.refBody, '#document'));
            var relativePos = reference.getBoundingClientRect();

            dom.style.width = fWidth;
            dom.style.height = fHeight;
            dom.style.backgroundColor = option.backColor || "white";
            dom.style.borderWidth = option.borderWidth || '1px';
            dom.style.borderColor = option.borderColor || "black";
            dom.style.borderStyle = option.borderStyle || "solid";

            if(direction == 'up'){
                dom.style.top = (pos.top + relativePos.top + relativePos.height + dom.offsetHeight) + 'px';
                dom.style.left = (pos.left + relativePos.left) + 'px';
            }else if(direction == 'left'){
                dom.style.top = (pos.top + relativePos.top) + 'px';
                dom.style.left = (pos.left + relativePos.left - dom.offsetWidth) + 'px';
            }else if(direction == 'right'){
                dom.style.top = (pos.top + relativePos.top) + 'px';
                dom.style.left = (pos.left + relativePos.left + dom.offsetWidth) + 'px';
            }else{
                dom.style.top = (pos.top + relativePos.top + relativePos.height) + 'px';
                dom.style.left = (pos.left + relativePos.left) + 'px';
            }
            dom.innerHTML = htmlStr;
            dom.style.display = 'block';

            var mouseListen = function(ev) {
                if(ev.target != mouseListen.unListenDom && ev.target.id != mouseListen.unListenId){

                    function checkParent(tar){
                        if(tar.parentNode == null) {
                            return false;
                        }else if(tar.parentNode == mouseListen.unListenDom){
                            return true;
                        }else{
                            return checkParent(tar.parentNode);
                        }
                    }
                    if(!checkParent(ev.target)){
                        dom.style.display = 'none';
                    }
                }
            }

            mouseListen.unListenDom = this.reference;
            mouseListen.unListenId = this.domId;
            this.refBody.onmousedown = window.document.onmousedown = mouseListen;


            if(option.intermediary != undefined && option.intermediary != null){
                window[option.intermediary.intermediaryName] = option.intermediary.data;
            }
        },
        destroy : function () {
            dom.style.display = 'none';
            dom.innerHTML = '';
        },
        listenEvent : function (dom, eventName, fn) {
            var data = this;
            dom[eventName] = function () {
                fn(data);
            }
        }
    };

    return obj;
};